package com.bestlink.starterdemo.config;

import com.bestlink.starterdemo.properties.StarterServiceProperties;
import com.bestlink.starterdemo.service.StarterServiceImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author jeffrey
 * @date 3/8/21 4:46 PM
 */
@Configuration
@ConditionalOnClass(StarterServiceImpl.class)
@EnableConfigurationProperties(StarterServiceProperties.class)
public class StarterConfigure {

    @Resource
    private StarterServiceProperties properties;

    @Bean
    @ConditionalOnBean
//    @ConditionalOnProperty(prefix = "demo.service", value = "enabled", havingValue = "true")
    public StarterServiceImpl starterService() {
        return new StarterServiceImpl(properties.getConfig());
    }
}
